/**
 * Created by Administrator on 2017/2/27.
 */
/**
 * 登录界面
 * @param ctx
 * @param next
 * @returns {Promise.<void>}
 */
var fn_login = async (ctx,next)=>{
    ctx.body = `<h1>登录</h1><br>
        <form action="/signin" method="post">
            <p>name:<input type="text" name="name"/></p>
            <p>passward:<input type="password" name="passward"/></p>
            <button type="submit">登录</button>
        </form>`;
}
/**
 * 登录处理
 * @param ctx
 * @param next
 * @returns {Promise.<void>}
 */
var fn_signin = async(ctx,next)=>{
    var name = ctx.request.body.name || '',//如果值不存在的话就默认''
        passward = ctx.request.body.passward || '';
    if(name==='cjw'&& passward==='123456'){
        ctx.body = `<h1>登录成功！欢迎你 ${name}</h1>`
    }else{
        ctx.body = '<h1>登录失败！</h1>'
    }
}

/**
 * 暴露函数接口
 * @type {{GET/: ((p1:*, p2:*)), POST/: ((p1:*, p2:*))}}
 */
module.exports = {
    'GET /':fn_login,
    'POST /signin':fn_signin
}
